package com.cc.config;

import org.springframework.web.filter.CharacterEncodingFilter;
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;

import javax.servlet.Filter;


public class WebConfig extends AbstractAnnotationConfigDispatcherServletInitializer {

    @Override
    protected Class<?>[] getRootConfigClasses() {
        // 根容器配置 创建spring容器
        return new Class[]{SpringConfig.class};
    }


    @Override
    protected Class<?>[] getServletConfigClasses() {
        //创建springMvc容器
        return new Class[]{SpringMvcConfig.class};
    }


    @Override
    protected String[] getServletMappings() {
        // 配置dispatcherServlet的映射规则，即url-pattern
        return new String[]{"/"};
    }


    @Override
    protected Filter[] getServletFilters() {
        // 创建过滤器 中文编码过滤器
        CharacterEncodingFilter filter = new CharacterEncodingFilter();
        filter.setEncoding("UTF-8");


        return new Filter[]{filter};
    }

}
